package com.ruoyi.project.module.bydpact.controller;

import java.util.List;

import com.ruoyi.common.utils.poi.ExcelUtil;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import com.ruoyi.framework.aspectj.lang.annotation.Log;
import com.ruoyi.framework.aspectj.lang.enums.BusinessType;
import com.ruoyi.project.module.bydpact.domain.Bydpact;
import com.ruoyi.project.module.bydpact.service.IBydpactService;
import com.ruoyi.framework.web.controller.BaseController;
import com.ruoyi.framework.web.page.TableDataInfo;
import com.ruoyi.framework.web.domain.AjaxResult;

/**
 * 合同管理 信息操作处理
 * 
 * @author ruoyi
 * @date 2018-11-15
 */
@Controller
@RequestMapping("/module/bydpact")
public class BydpactController extends BaseController
{
    private String prefix = "module/bydpact";
	
	@Autowired
	private IBydpactService bydpactService;
	
	@RequiresPermissions("module:bydpact:view")
	@GetMapping()
	public String bydpact()
	{
	    return prefix + "/bydpact";
	}
	
	/**
	 * 查询合同管理列表
	 */
	@RequiresPermissions("module:bydpact:list")
	@PostMapping("/list")
	@ResponseBody
	public TableDataInfo list(Bydpact bydpact)
	{
		startPage();
        List<Bydpact> list = bydpactService.selectBydpactList(bydpact);
		return getDataTable(list);
	}
	@Log(title = "参数管理", businessType = BusinessType.EXPORT)
	@RequiresPermissions("system:bydpact:export")
	@PostMapping("/export")
	@ResponseBody
	public AjaxResult export(Bydpact bydpact) throws Exception
	{
		try
		{
			List<Bydpact> list = bydpactService.selectBydpactList(bydpact);
			ExcelUtil<Bydpact> util = new ExcelUtil<Bydpact>(Bydpact.class);
			return util.exportExcel(list, "bydpact");
		}
		catch (Exception e)
		{
			return error("导出Excel失败，请联系网站管理员！");
		}
	}
	/**
	 * 新增合同管理
	 */
	@GetMapping("/add")
	public String add()
	{
	    return prefix + "/add";
	}

	/**
	 * 新增保存合同管理
	 */
	@RequiresPermissions("module:bydpact:add")
	@Log(title = "合同管理", businessType = BusinessType.INSERT)
	@PostMapping("/add")
	@ResponseBody
	public AjaxResult addSave(Bydpact bydpact)
	{		
		return toAjax(bydpactService.insertBydpact(bydpact));
	}

	/**
	 * 修改合同管理
	 */
	@GetMapping("/edit/{id}")
	public String edit(@PathVariable("id") Integer id, ModelMap mmap)
	{
		Bydpact bydpact = bydpactService.selectBydpactById(id);
		mmap.put("bydpact", bydpact);
	    return prefix + "/edit";
	}
	
	/**
	 * 修改保存合同管理
	 */
	@RequiresPermissions("module:bydpact:edit")
	@Log(title = "合同管理", businessType = BusinessType.UPDATE)
	@PostMapping("/edit")
	@ResponseBody
	public AjaxResult editSave(Bydpact bydpact)
	{		
		return toAjax(bydpactService.updateBydpact(bydpact));
	}
	
	/**
	 * 删除合同管理
	 */
	@RequiresPermissions("module:bydpact:remove")
	@Log(title = "合同管理", businessType = BusinessType.DELETE)
	@PostMapping( "/remove")
	@ResponseBody
	public AjaxResult remove(String ids)
	{		
		return toAjax(bydpactService.deleteBydpactByIds(ids));
	}
	
}
